package com.rd.student.jike.class2.xuezhixin.Work719;

public class Work04 extends Thread{

    D d;

    public Work04(D d,String name) {
        super(name);
        this.d = d;
    }

    @Override
    public void run() {
        synchronized (d) {
            try{
                Thread.sleep(500);
            }catch (Exception e){
                e.printStackTrace();
            }
            d.add();
            System.out.println(getName() + " 第 " + d.i + " 个通过山洞");
        }
    }

    public static void main(String[] args) {
        D d = new D();
        new Work04(d,"阿一").start();
        new Work04(d,"阿二").start();
        new Work04(d,"阿三").start();
        new Work04(d,"阿四").start();
        new Work04(d,"阿五").start();
        new Work04(d,"阿六").start();
        new Work04(d,"阿七").start();
        new Work04(d,"阿八").start();
        new Work04(d,"阿九").start();
        new Work04(d,"阿十").start();
    }
}

class D{
    static volatile int i;

    public static void add(){
        i++;
    }
}
